package com.lc.big_event.service.Impl;

import com.lc.big_event.mapper.CategoryMapper;
import com.lc.big_event.pojo.Category;
import com.lc.big_event.service.CategoryService;
import com.lc.big_event.untils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author liuchun
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    /**
     * 新增文章分类
     * @param category
     */
    public void add(Category category) {
        //补充参数
        Map<String,Object> claims = ThreadLocalUtil.get();
        Integer id = (Integer) claims.get("id");
        category.setCreateUser(id);
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.add(category);
    }

    /**
     * 文章分类列表
     * @return
     */
    public List<Category> list() {
        Map<String,Object> claims = ThreadLocalUtil.get();
        Integer userId = (Integer) claims.get("id");
        return categoryMapper.list(userId);
    }

    /**
     * 获取文章分类详情
     * @param id
     * @return
     */
    public Category detail(Integer id) {
        return categoryMapper.detail(id);
    }

    /**
     * 更新文章分类
     * @param category
     */
    public void updateArticle(Category category) {
        categoryMapper.updateArticle(category);
    }

    /**
     * 删除文章分类
     * @param id
     */
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }
}
